package logic

import (
	"context"
	"fmt"
	"housing/models/mysql"
	"strings"

	"housing/houserpc/houserpc"
	"housing/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SeekLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSeekLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SeekLogic {
	return &SeekLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SeekLogic) Seek(in *houserpc.SeekRequest) (*houserpc.SeekResponse, error) {
	// todo: add your logic here and delete this line

	//var user mysql.User
	//
	//mysql.DB.Debug().Where("id=?", in.UserId).Find(&user)
	//
	//if user.ID == 0 {
	//	return nil, fmt.Errorf("当前用户不存在,不允许咨询")
	//}
	//
	//var house mysql.User
	//
	//mysql.DB.Debug().Where("house_id=?", in.HouseId).Find(&house)
	//
	//if house.ID == 0 {
	//	return nil, fmt.Errorf("当前房源不存在,不允许咨询")
	//}

	if strings.Contains(in.Comment, "中介费") || strings.Contains(in.Comment, "虚假") {
		return nil, fmt.Errorf("当前咨询内容出现敏感词汇,不允许咨询")
	}
	seek := mysql.Seek{

		UserId:  in.UserId,
		HouseId: in.HouseId,
		Comment: in.Comment,
	}
	mysql.DB.Debug().Create(&seek)
	return &houserpc.SeekResponse{
		SeekId: int64(seek.ID),
	}, nil
}
